﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WooCoo.Authorization
{
    /// <summary>
    /// 基于角色的资源权限对象
    /// </summary>
    /// <remarks>
    /// 应用RBAC控制方式。
    /// 资源定义：根据用户可见级别与完整性区分。菜单，按钮，URL，文件夹，文件，数据库表。
    /// </remarks>
    public class ResourceRight : ICloneable
    {
        /// <summary>
        /// 角色ID
        /// </summary>
        public string RoleID { get; set; }
        /// <summary>
        /// 对象名
        /// </summary>
        public string ObjectName { get; set; }
        /// <summary>
        /// 是否可读
        /// </summary>
        public bool IsCanSelect { get; set; }
        /// <summary>
        /// 是否可增
        /// </summary>
        public bool IsCanInsert { get; set; }
        /// <summary>
        /// 是否可更新
        /// </summary>
        public bool IsCanUpdate { get; set; }
        /// <summary>
        /// 是否可更新
        /// </summary>
        public bool IsCanDelete { get; set; }

        /// <summary>
        /// 是否控制
        /// </summary>
        public bool IsControl { get; set; }

        /// <summary>
        /// 成员列表
        /// </summary>
        public List<MemberRight> FieldRightList { get; set; }

        public ResourceRight()
        {
            IsControl = true;
            FieldRightList = new List<MemberRight>();
        }

        #region ICloneable 成员

        public object Clone()
        {
            ResourceRight or = new ResourceRight();
            or.RoleID = this.RoleID;
            or.ObjectName = this.ObjectName;
            or.IsCanSelect = this.IsCanSelect;
            or.IsCanInsert = this.IsCanInsert;
            or.IsCanDelete = this.IsCanDelete;
            or.IsCanUpdate = this.IsCanUpdate;
            or.IsControl = this.IsControl;
            //or.FieldRightList.AddRange(this.FieldRightList.CopyTo();
            foreach (var item in this.FieldRightList)
            {
                MemberRight fr = item.Clone() as MemberRight;
                or.FieldRightList.Add(fr);
            }
            return or;
        }

        #endregion
    }
}
